<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Containers - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.navigation.containers.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.navigation.containers.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.navigation.pages.html">Pages</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.navigation.html">Zend_Navigation</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.oauth.html">Zend_Oauth</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.navigation.containers" class="section"><div class="info"><h1 class="title">Containers</h1></div>
    

    <p class="para">
        Containers have methods for adding, retrieving, deleting and
        iterating pages. Containers implement the
        <a href="http://php.net/spl" class="link external">&raquo; SPL</a> interfaces
        <span class="classname">RecursiveIterator</span> and
        <span class="classname">Countable</span>, meaning that a container can
        be iterated using the SPL
        <span class="classname">RecursiveIteratorIterator</span> class.
    </p>

    <div class="section" id="zend.navigation.containers.creating"><div class="info"><h1 class="title">Creating containers</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Navigation_Container</span> is
            abstract, and can not be instantiated directly. Use
            <span class="classname">Zend_Navigation</span> if you want to
            instantiate a container.
        </p>

        <p class="para">
            <span class="classname">Zend_Navigation</span> can be constructed
            entirely empty, or take an array or a
            <span class="classname">Zend_Config</span> object with pages to put in the
            container. Each page in the given array/config will eventually be
            passed to the  <span class="methodname">addPage()</span> method of the container class,
            which means that each element in the array/config can be an array or
            a config object, or a <span class="classname">Zend_Navigation_Page</span>
            instance.
        </p>

        <div class="example" id="zend.navigation.containers.creating.example.array"><div class="info"><p><b>Example #1 Creating a container using an array</b></p></div>
            

            <pre class="programlisting brush: php">
/*
 * Create a container from an array
 *
 * Each element in the array will be passed to
 * Zend_Navigation_Page::factory() when constructing.
 */
$container = new Zend_Navigation(array(
    array(
        &#039;label&#039; =&gt; &#039;Page 1&#039;,
        &#039;id&#039; =&gt; &#039;home-link&#039;,
        &#039;uri&#039; =&gt; &#039;/&#039;
    ),
    array(
        &#039;label&#039; =&gt; &#039;Zend&#039;,
        &#039;uri&#039; =&gt; &#039;http://www.zend-project.com/&#039;,
        &#039;order&#039; =&gt; 100
    ),
    array(
        &#039;label&#039; =&gt; &#039;Page 2&#039;,
        &#039;controller&#039; =&gt; &#039;page2&#039;,
        &#039;pages&#039; =&gt; array(
            array(
                &#039;label&#039; =&gt; &#039;Page 2.1&#039;,
                &#039;action&#039; =&gt; &#039;page2_1&#039;,
                &#039;controller&#039; =&gt; &#039;page2&#039;,
                &#039;class&#039; =&gt; &#039;special-one&#039;,
                &#039;title&#039; =&gt; &#039;This element has a special class&#039;,
                &#039;active&#039; =&gt; true
            ),
            array(
                &#039;label&#039; =&gt; &#039;Page 2.2&#039;,
                &#039;action&#039; =&gt; &#039;page2_2&#039;,
                &#039;controller&#039; =&gt; &#039;page2&#039;,
                &#039;class&#039; =&gt; &#039;special-two&#039;,
                &#039;title&#039; =&gt; &#039;This element has a special class too&#039;
            )
        )
    ),
    array(
        &#039;label&#039; =&gt; &#039;Page 2 with params&#039;,
        &#039;action&#039; =&gt; &#039;index&#039;,
        &#039;controller&#039; =&gt; &#039;page2&#039;,
        // specify a param or two
        &#039;params&#039; =&gt; array(
            &#039;format&#039; =&gt; &#039;json&#039;,
            &#039;foo&#039; =&gt; &#039;bar&#039;
        )
    ),
    array(
        &#039;label&#039; =&gt; &#039;Page 2 with params and a route&#039;,
        &#039;action&#039; =&gt; &#039;index&#039;,
        &#039;controller&#039; =&gt; &#039;page2&#039;,
        // specify a route name and a param for the route
        &#039;route&#039; =&gt; &#039;nav-route-example&#039;,
        &#039;params&#039; =&gt; array(
            &#039;format&#039; =&gt; &#039;json&#039;
        )
    ),
    array(
        &#039;label&#039; =&gt; &#039;Page 3&#039;,
        &#039;action&#039; =&gt; &#039;index&#039;,
        &#039;controller&#039; =&gt; &#039;index&#039;,
        &#039;module&#039; =&gt; &#039;mymodule&#039;,
        &#039;reset_params&#039; =&gt; false
    ),
    array(
        &#039;label&#039; =&gt; &#039;Page 4&#039;,
        &#039;uri&#039; =&gt; &#039;#&#039;,
        &#039;pages&#039; =&gt; array(
            array(
                &#039;label&#039; =&gt; &#039;Page 4.1&#039;,
                &#039;uri&#039; =&gt; &#039;/page4&#039;,
                &#039;title&#039; =&gt; &#039;Page 4 using uri&#039;,
                &#039;pages&#039; =&gt; array(
                    array(
                        &#039;label&#039; =&gt; &#039;Page 4.1.1&#039;,
                        &#039;title&#039; =&gt; &#039;Page 4 using mvc params&#039;,
                        &#039;action&#039; =&gt; &#039;index&#039;,
                        &#039;controller&#039; =&gt; &#039;page4&#039;,
                        // let&#039;s say this page is active
                        &#039;active&#039; =&gt; &#039;1&#039;
                    )
                )
            )
        )
    ),
    array(
        &#039;label&#039; =&gt; &#039;Page 0?&#039;,
        &#039;uri&#039; =&gt; &#039;/setting/the/order/option&#039;,
        // setting order to -1 should make it appear first
        &#039;order&#039; =&gt; -1
    ),
    array(
        &#039;label&#039; =&gt; &#039;Page 5&#039;,
        &#039;uri&#039; =&gt; &#039;/&#039;,
        // this page should not be visible
        &#039;visible&#039; =&gt; false,
        &#039;pages&#039; =&gt; array(
            array(
                &#039;label&#039; =&gt; &#039;Page 5.1&#039;,
                &#039;uri&#039; =&gt; &#039;#&#039;,
                &#039;pages&#039; =&gt; array(
                    array(
                        &#039;label&#039; =&gt; &#039;Page 5.1.1&#039;,
                        &#039;uri&#039; =&gt; &#039;#&#039;,
                        &#039;pages&#039; =&gt; array(
                            array(
                                &#039;label&#039; =&gt; &#039;Page 5.1.2&#039;,
                                &#039;uri&#039; =&gt; &#039;#&#039;,
                                // let&#039;s say this page is active
                                &#039;active&#039; =&gt; true
                            )
                        )
                    )
                )
            )
        )
    ),
    array(
        &#039;label&#039; =&gt; &#039;ACL page 1 (guest)&#039;,
        &#039;uri&#039; =&gt; &#039;#acl-guest&#039;,
        &#039;resource&#039; =&gt; &#039;nav-guest&#039;,
        &#039;pages&#039; =&gt; array(
            array(
                &#039;label&#039; =&gt; &#039;ACL page 1.1 (foo)&#039;,
                &#039;uri&#039; =&gt; &#039;#acl-foo&#039;,
                &#039;resource&#039; =&gt; &#039;nav-foo&#039;
            ),
            array(
                &#039;label&#039; =&gt; &#039;ACL page 1.2 (bar)&#039;,
                &#039;uri&#039; =&gt; &#039;#acl-bar&#039;,
                &#039;resource&#039; =&gt; &#039;nav-bar&#039;
            ),
            array(
                &#039;label&#039; =&gt; &#039;ACL page 1.3 (baz)&#039;,
                &#039;uri&#039; =&gt; &#039;#acl-baz&#039;,
                &#039;resource&#039; =&gt; &#039;nav-baz&#039;
            ),
            array(
                &#039;label&#039; =&gt; &#039;ACL page 1.4 (bat)&#039;,
                &#039;uri&#039; =&gt; &#039;#acl-bat&#039;,
                &#039;resource&#039; =&gt; &#039;nav-bat&#039;
            )
        )
    ),
    array(
        &#039;label&#039; =&gt; &#039;ACL page 2 (member)&#039;,
        &#039;uri&#039; =&gt; &#039;#acl-member&#039;,
        &#039;resource&#039; =&gt; &#039;nav-member&#039;
    ),
    array(
        &#039;label&#039; =&gt; &#039;ACL page 3 (admin&#039;,
        &#039;uri&#039; =&gt; &#039;#acl-admin&#039;,
        &#039;resource&#039; =&gt; &#039;nav-admin&#039;,
        &#039;pages&#039; =&gt; array(
            array(
                &#039;label&#039; =&gt; &#039;ACL page 3.1 (nothing)&#039;,
                &#039;uri&#039; =&gt; &#039;#acl-nada&#039;
            )
        )
    ),
    array(
        &#039;label&#039; =&gt; &#039;Zend Framework&#039;,
        &#039;route&#039; =&gt; &#039;zf-route&#039;
    )
));
</pre>

        </div>

        <div class="example" id="zend.navigation.containers.creating.example.config"><div class="info"><p><b>Example #2 Creating a container using a config object</b></p></div>
            

            <pre class="programlisting brush: php">
/* CONTENTS OF /path/to/navigation.xml:
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;config&gt;
    &lt;nav&gt;

        &lt;zend&gt;
            &lt;label&gt;Zend&lt;/label&gt;
            &lt;uri&gt;http://www.zend-project.com/&lt;/uri&gt;
            &lt;order&gt;100&lt;/order&gt;
        &lt;/zend&gt;

        &lt;page1&gt;
            &lt;label&gt;Page 1&lt;/label&gt;
            &lt;uri&gt;page1&lt;/uri&gt;
            &lt;pages&gt;

                &lt;page1_1&gt;
                    &lt;label&gt;Page 1.1&lt;/label&gt;
                    &lt;uri&gt;page1/page1_1&lt;/uri&gt;
                &lt;/page1_1&gt;

            &lt;/pages&gt;
        &lt;/page1&gt;

        &lt;page2&gt;
            &lt;label&gt;Page 2&lt;/label&gt;
            &lt;uri&gt;page2&lt;/uri&gt;
            &lt;pages&gt;

                &lt;page2_1&gt;
                    &lt;label&gt;Page 2.1&lt;/label&gt;
                    &lt;uri&gt;page2/page2_1&lt;/uri&gt;
                &lt;/page2_1&gt;

                &lt;page2_2&gt;
                    &lt;label&gt;Page 2.2&lt;/label&gt;
                    &lt;uri&gt;page2/page2_2&lt;/uri&gt;
                    &lt;pages&gt;

                        &lt;page2_2_1&gt;
                            &lt;label&gt;Page 2.2.1&lt;/label&gt;
                            &lt;uri&gt;page2/page2_2/page2_2_1&lt;/uri&gt;
                        &lt;/page2_2_1&gt;

                        &lt;page2_2_2&gt;
                            &lt;label&gt;Page 2.2.2&lt;/label&gt;
                            &lt;uri&gt;page2/page2_2/page2_2_2&lt;/uri&gt;
                            &lt;active&gt;1&lt;/active&gt;
                        &lt;/page2_2_2&gt;

                    &lt;/pages&gt;
                &lt;/page2_2&gt;

                &lt;page2_3&gt;
                    &lt;label&gt;Page 2.3&lt;/label&gt;
                    &lt;uri&gt;page2/page2_3&lt;/uri&gt;
                    &lt;pages&gt;

                        &lt;page2_3_1&gt;
                            &lt;label&gt;Page 2.3.1&lt;/label&gt;
                            &lt;uri&gt;page2/page2_3/page2_3_1&lt;/uri&gt;
                        &lt;/page2_3_1&gt;

                        &lt;page2_3_2&gt;
                            &lt;label&gt;Page 2.3.2&lt;/label&gt;
                            &lt;uri&gt;page2/page2_3/page2_3_2&lt;/uri&gt;
                            &lt;visible&gt;0&lt;/visible&gt;
                            &lt;pages&gt;

                                    &lt;page2_3_2_1&gt;
                                        &lt;label&gt;Page 2.3.2.1&lt;/label&gt;
                                        &lt;uri&gt;page2/page2_3/page2_3_2/1&lt;/uri&gt;
                                        &lt;active&gt;1&lt;/active&gt;
                                    &lt;/page2_3_2_1&gt;

                                    &lt;page2_3_2_2&gt;
                                        &lt;label&gt;Page 2.3.2.2&lt;/label&gt;
                                        &lt;uri&gt;page2/page2_3/page2_3_2/2&lt;/uri&gt;
                                        &lt;active&gt;1&lt;/active&gt;

                                        &lt;pages&gt;
                                            &lt;page_2_3_2_2_1&gt;
                                                &lt;label&gt;Ignore&lt;/label&gt;
                                                &lt;uri&gt;#&lt;/uri&gt;
                                                &lt;active&gt;1&lt;/active&gt;
                                            &lt;/page_2_3_2_2_1&gt;
                                        &lt;/pages&gt;
                                    &lt;/page2_3_2_2&gt;

                            &lt;/pages&gt;
                        &lt;/page2_3_2&gt;

                        &lt;page2_3_3&gt;
                            &lt;label&gt;Page 2.3.3&lt;/label&gt;
                            &lt;uri&gt;page2/page2_3/page2_3_3&lt;/uri&gt;
                            &lt;resource&gt;admin&lt;/resource&gt;
                            &lt;pages&gt;

                                    &lt;page2_3_3_1&gt;
                                        &lt;label&gt;Page 2.3.3.1&lt;/label&gt;
                                        &lt;uri&gt;page2/page2_3/page2_3_3/1&lt;/uri&gt;
                                        &lt;active&gt;1&lt;/active&gt;
                                    &lt;/page2_3_3_1&gt;

                                    &lt;page2_3_3_2&gt;
                                        &lt;label&gt;Page 2.3.3.2&lt;/label&gt;
                                        &lt;uri&gt;page2/page2_3/page2_3_3/2&lt;/uri&gt;
                                        &lt;resource&gt;guest&lt;/resource&gt;
                                        &lt;active&gt;1&lt;/active&gt;
                                    &lt;/page2_3_3_2&gt;

                            &lt;/pages&gt;
                        &lt;/page2_3_3&gt;

                    &lt;/pages&gt;
                &lt;/page2_3&gt;

            &lt;/pages&gt;
        &lt;/page2&gt;

        &lt;page3&gt;
            &lt;label&gt;Page 3&lt;/label&gt;
            &lt;uri&gt;page3&lt;/uri&gt;
            &lt;pages&gt;

                &lt;page3_1&gt;
                    &lt;label&gt;Page 3.1&lt;/label&gt;
                    &lt;uri&gt;page3/page3_1&lt;/uri&gt;
                    &lt;resource&gt;guest&lt;/resource&gt;
                &lt;/page3_1&gt;

                &lt;page3_2&gt;
                    &lt;label&gt;Page 3.2&lt;/label&gt;
                    &lt;uri&gt;page3/page3_2&lt;/uri&gt;
                    &lt;resource&gt;member&lt;/resource&gt;
                    &lt;pages&gt;

                        &lt;page3_2_1&gt;
                            &lt;label&gt;Page 3.2.1&lt;/label&gt;
                            &lt;uri&gt;page3/page3_2/page3_2_1&lt;/uri&gt;
                        &lt;/page3_2_1&gt;

                        &lt;page3_2_2&gt;
                            &lt;label&gt;Page 3.2.2&lt;/label&gt;
                            &lt;uri&gt;page3/page3_2/page3_2_2&lt;/uri&gt;
                            &lt;resource&gt;admin&lt;/resource&gt;
                        &lt;/page3_2_2&gt;

                    &lt;/pages&gt;
                &lt;/page3_2&gt;

                &lt;page3_3&gt;
                    &lt;label&gt;Page 3.3&lt;/label&gt;
                    &lt;uri&gt;page3/page3_3&lt;/uri&gt;
                    &lt;resource&gt;special&lt;/resource&gt;
                    &lt;pages&gt;

                        &lt;page3_3_1&gt;
                            &lt;label&gt;Page 3.3.1&lt;/label&gt;
                            &lt;uri&gt;page3/page3_3/page3_3_1&lt;/uri&gt;
                            &lt;visible&gt;0&lt;/visible&gt;
                        &lt;/page3_3_1&gt;

                        &lt;page3_3_2&gt;
                            &lt;label&gt;Page 3.3.2&lt;/label&gt;
                            &lt;uri&gt;page3/page3_3/page3_3_2&lt;/uri&gt;
                            &lt;resource&gt;admin&lt;/resource&gt;
                        &lt;/page3_3_2&gt;

                    &lt;/pages&gt;
                &lt;/page3_3&gt;

            &lt;/pages&gt;
        &lt;/page3&gt;

        &lt;home&gt;
            &lt;label&gt;Home&lt;/label&gt;
            &lt;order&gt;-100&lt;/order&gt;
            &lt;module&gt;default&lt;/module&gt;
            &lt;controller&gt;index&lt;/controller&gt;
            &lt;action&gt;index&lt;/action&gt;
        &lt;/home&gt;

    &lt;/nav&gt;
&lt;/config&gt;
 */

$config = new Zend_Config_Xml(&#039;/path/to/navigation.xml&#039;, &#039;nav&#039;);
$container = new Zend_Navigation($config);
</pre>

        </div>
    </div>

    <div class="section" id="zend.navigation.containers.adding"><div class="info"><h1 class="title">Adding pages</h1></div>
        

        <p class="para">
            Adding pages to a container can be done with the methods
             <span class="methodname">addPage()</span>,  <span class="methodname">addPages()</span>, or
             <span class="methodname">setPages()</span>. See examples below for explanation.
        </p>

        <div class="example" id="zend.navigation.containers.adding.example"><div class="info"><p><b>Example #3 Adding pages to a container</b></p></div>
            

            <pre class="programlisting brush: php">
// create container
$container = new Zend_Navigation();

// add page by giving a page instance
$container-&gt;addPage(Zend_Navigation_Page::factory(array(
    &#039;uri&#039; =&gt; &#039;http://www.example.com/&#039;
)))

// add page by giving an array
$container-&gt;addPage(array(
    &#039;uri&#039; =&gt; &#039;http://www.example.com/&#039;
)))

// add page by giving a config object
$container-&gt;addPage(new Zend_Config(array(
    &#039;uri&#039; =&gt; &#039;http://www.example.com/&#039;
)))

$pages = array(
    array(
        &#039;label&#039;  =&gt; &#039;Save&#039;
        &#039;action&#039; =&gt; &#039;save&#039;,
    ),
    array(
        &#039;label&#039; =&gt;  &#039;Delete&#039;,
        &#039;action&#039; =&gt; &#039;delete&#039;
    )
);

// add two pages
$container-&gt;addPages($pages);

// remove existing pages and add the given pages
$container-&gt;setPages($pages);
</pre>

        </div>
    </div>

    <div class="section" id="zend.navigation.containers.removing"><div class="info"><h1 class="title">Removing pages</h1></div>
        

        <p class="para">
            Removing pages can be done with  <span class="methodname">removePage()</span> or
             <span class="methodname">removePages()</span>. The first method accepts a an instance
            of a page, or an integer. The integer corresponds to the
            <span class="property">order</span> a page has. The latter method will remove all
            pages in the container.
        </p>

        <div class="example" id="zend.navigation.containers.removing.example"><div class="info"><p><b>Example #4 Removing pages from a container</b></p></div>
            

            <pre class="programlisting brush: php">
$container = new Zend_Navigation(array(
    array(
        &#039;label&#039;  =&gt; &#039;Page 1&#039;,
        &#039;action&#039; =&gt; &#039;page1&#039;
    ),
    array(
        &#039;label&#039;  =&gt; &#039;Page 2&#039;,
        &#039;action&#039; =&gt; &#039;page2&#039;,
        &#039;order&#039;  =&gt; 200
    ),
    array(
        &#039;label&#039;  =&gt; &#039;Page 3&#039;,
        &#039;action&#039; =&gt; &#039;page3&#039;
    )
));

// remove page by implicit page order
$container-&gt;removePage(0);      // removes Page 1

// remove page by instance
$page3 = $container-&gt;findOneByAction(&#039;Page 3&#039;);
$container-&gt;removePage($page3); // removes Page 3

// remove page by explicit page order
$container-&gt;removePage(200);    // removes Page 2

// remove all pages
$container-&gt;removePages();      // removes all pages
</pre>

        </div>
    </div>

    <div class="section" id="zend.navigation.containers.finding"><div class="info"><h1 class="title">Finding pages</h1></div>
        

        <p class="para">
            Containers have finder methods for retrieving pages.
            They are  <span class="methodname">findOneBy($property, $value)</span>,
             <span class="methodname">findAllBy($property, $value)</span>, and
             <span class="methodname">findBy($property, $value, $all = false)</span>.
            Those methods will recursively search the container for
            pages matching the given <strong class="command">$page-&gt;$property == $value</strong>.
            The first method,  <span class="methodname">findOneBy()</span>, will return a
            single page matching the property with the given value, or
            <b><tt>NULL</tt></b> if it cannot be found. The second method will return
            all pages with a property matching the given value. The third
            method will call one of the two former methods depending on the
            <var class="varname">$all</var> flag.
        </p>

        <p class="para">
            The finder methods can also be used magically by appending the
            property name to <span class="property">findBy</span>, <span class="property">findOneBy</span>, or
            <span class="property">findAllBy</span>, e.g.  <span class="methodname">findOneByLabel(&#039;Home&#039;)</span> to
            return the first matching page with label &#039;Home&#039;.
            Other combinations are  <span class="methodname">findByLabel(...)</span>,
             <span class="methodname">findOnyByTitle(...)</span>,
             <span class="methodname">findAllByController(...)</span>, etc. Finder
            methods also work on custom properties, such as
             <span class="methodname">findByFoo(&#039;bar&#039;)</span>.
        </p>

        <div class="example" id="zend.navigation.containers.finding.example"><div class="info"><p><b>Example #5 Finding pages in a container</b></p></div>
            

            <pre class="programlisting brush: php">
$container = new Zend_Navigation(array(
    array(
        &#039;label&#039; =&gt; &#039;Page 1&#039;,
        &#039;uri&#039;   =&gt; &#039;page-1&#039;,
        &#039;foo&#039;   =&gt; &#039;bar&#039;,
        &#039;pages&#039; =&gt; array(
            array(
                &#039;label&#039; =&gt; &#039;Page 1.1&#039;,
                &#039;uri&#039;   =&gt; &#039;page-1.1&#039;,
                &#039;foo&#039;   =&gt; &#039;bar&#039;,
            ),
            array(
                &#039;label&#039; =&gt; &#039;Page 1.2&#039;,
                &#039;uri&#039;   =&gt; &#039;page-1.2&#039;,
                &#039;class&#039; =&gt; &#039;my-class&#039;,
            ),
            array(
                &#039;type&#039;   =&gt; &#039;uri&#039;,
                &#039;label&#039;  =&gt; &#039;Page 1.3&#039;,
                &#039;uri&#039;    =&gt; &#039;page-1.3&#039;,
                &#039;action&#039; =&gt; &#039;about&#039;
            )
        )
    ),
    array(
        &#039;label&#039;      =&gt; &#039;Page 2&#039;,
        &#039;id&#039;         =&gt; &#039;page_2_and_3&#039;,
        &#039;class&#039;      =&gt; &#039;my-class&#039;,
        &#039;module&#039;     =&gt; &#039;page2&#039;,
        &#039;controller&#039; =&gt; &#039;index&#039;,
        &#039;action&#039;     =&gt; &#039;page1&#039;
    ),
    array(
        &#039;label&#039;      =&gt; &#039;Page 3&#039;,
        &#039;id&#039;         =&gt; &#039;page_2_and_3&#039;,
        &#039;module&#039;     =&gt; &#039;page3&#039;,
        &#039;controller&#039; =&gt; &#039;index&#039;
    )
));

// The &#039;id&#039; is not required to be unique, but be aware that
// having two pages with the same id will render the same id attribute
// in menus and breadcrumbs.
$found = $container-&gt;findBy(&#039;id&#039;,
                            &#039;page_2_and_3&#039;);      // returns Page 2
$found = $container-&gt;findOneBy(&#039;id&#039;,
                               &#039;page_2_and_3&#039;);   // returns Page 2
$found = $container-&gt;findBy(&#039;id&#039;,
                            &#039;page_2_and_3&#039;,
                            true);                // returns Page 2 and Page 3
$found = $container-&gt;findById(&#039;page_2_and_3&#039;);    // returns Page 2
$found = $container-&gt;findOneById(&#039;page_2_and_3&#039;); // returns Page 2
$found = $container-&gt;findAllById(&#039;page_2_and_3&#039;); // returns Page 2 and Page 3

// Find all matching CSS class my-class
$found = $container-&gt;findAllBy(&#039;class&#039;,
                               &#039;my-class&#039;);       // returns Page 1.2 and Page 2
$found = $container-&gt;findAllByClass(&#039;my-class&#039;);  // returns Page 1.2 and Page 2

// Find first matching CSS class my-class
$found = $container-&gt;findOneByClass(&#039;my-class&#039;);  // returns Page 1.2

// Find all matching CSS class non-existant
$found = $container-&gt;findAllByClass(&#039;non-existant&#039;); // returns array()

// Find first matching CSS class non-existant
$found = $container-&gt;findOneByClass(&#039;non-existant&#039;); // returns null

// Find all pages with custom property &#039;foo&#039; = &#039;bar&#039;
$found = $container-&gt;findAllBy(&#039;foo&#039;, &#039;bar&#039;); // returns Page 1 and Page 1.1

// To achieve the same magically, &#039;foo&#039; must be in lowercase.
// This is because &#039;foo&#039; is a custom property, and thus the
// property name is not normalized to &#039;Foo&#039;
$found = $container-&gt;findAllByfoo(&#039;bar&#039;);

// Find all with controller = &#039;index&#039;
$found = $container-&gt;findAllByController(&#039;index&#039;); // returns Page 2 and Page 3
</pre>

        </div>
    </div>

    <div class="section" id="zend.navigation.containers.iterating"><div class="info"><h1 class="title">Iterating containers</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Navigation_Container</span> implements
            <span class="classname">RecursiveIteratorIterator</span>, and can be
            iterated using any <span class="classname">Iterator</span> class. To iterate
            a container recursively, use the
            <span class="classname">RecursiveIteratorIterator</span> class.
        </p>

        <div class="example" id="zend.navigation.containers.iterating.example"><div class="info"><p><b>Example #6 Iterating a container</b></p></div>
            

            <pre class="programlisting brush: php">
/*
 * Create a container from an array
 */
$container = new Zend_Navigation(array(
    array(
        &#039;label&#039; =&gt; &#039;Page 1&#039;,
        &#039;uri&#039;   =&gt; &#039;#&#039;
    ),
    array(
        &#039;label&#039; =&gt; &#039;Page 2&#039;,
        &#039;uri&#039;   =&gt; &#039;#&#039;,
        &#039;pages&#039; =&gt; array(
            array(
                &#039;label&#039; =&gt; &#039;Page 2.1&#039;,
                &#039;uri&#039;   =&gt; &#039;#&#039;
            ),
            array(
                &#039;label&#039; =&gt; &#039;Page 2.2&#039;,
                &#039;uri&#039;   =&gt; &#039;#&#039;
            )
        )
    ),
    array(
        &#039;label&#039; =&gt; &#039;Page 3&#039;,
        &#039;uri&#039;   =&gt; &#039;#&#039;
    )
));

// Iterate flat using regular foreach:
// Output: Page 1, Page 2, Page 3
foreach ($container as $page) {
    echo $page-&gt;label;
}

// Iterate recursively using RecursiveIteratorIterator
$it = new RecursiveIteratorIterator(
        $container, RecursiveIteratorIterator::SELF_FIRST);

// Output: Page 1, Page 2, Page 2.1, Page 2.2, Page 3
foreach ($it as $page) {
    echo $page-&gt;label;
}
</pre>

        </div>
    </div>

    <div class="section" id="zend.navigation.containers.other"><div class="info"><h1 class="title">Other operations</h1></div>
        

        <p class="para">
            The method  <span class="methodname">hasPage(Zend_Navigation_Page $page)</span> checks
            if the container has the given page. The method  <span class="methodname">hasPages()</span>
            checks if there are any pages in the container, and is equivalent
            to <strong class="command">count($container) &gt; 1</strong>.
        </p>

        <p class="para">
            The  <span class="methodname">toArray()</span> method converts the container and the
            pages in it to an array. This can be useful for serializing and
            debugging.
        </p>

        <div class="example" id="zend.navigation.containers.other.example.toarray"><div class="info"><p><b>Example #7 Converting a container to an array</b></p></div>
            

            <pre class="programlisting brush: php">
$container = new Zend_Navigation(array(
    array(
        &#039;label&#039; =&gt; &#039;Page 1&#039;,
        &#039;uri&#039;   =&gt; &#039;#&#039;
    ),
    array(
        &#039;label&#039; =&gt; &#039;Page 2&#039;,
        &#039;uri&#039;   =&gt; &#039;#&#039;,
        &#039;pages&#039; =&gt; array(
            array(
                &#039;label&#039; =&gt; &#039;Page 2.1&#039;,
                &#039;uri&#039;   =&gt; &#039;#&#039;
            ),
            array(
                &#039;label&#039; =&gt; &#039;Page 2.2&#039;,
               &#039;uri&#039;   =&gt; &#039;#&#039;
            )
        )
    )
));

var_dump($container-&gt;toArray());

/* Output:
array(2) {
  [0]=&gt; array(15) {
    [&quot;label&quot;]=&gt; string(6) &quot;Page 1&quot;
    [&quot;id&quot;]=&gt; NULL
    [&quot;class&quot;]=&gt; NULL
    [&quot;title&quot;]=&gt; NULL
    [&quot;target&quot;]=&gt; NULL
    [&quot;rel&quot;]=&gt; array(0) {
    }
    [&quot;rev&quot;]=&gt; array(0) {
    }
    [&quot;order&quot;]=&gt; NULL
    [&quot;resource&quot;]=&gt; NULL
    [&quot;privilege&quot;]=&gt; NULL
    [&quot;active&quot;]=&gt; bool(false)
    [&quot;visible&quot;]=&gt; bool(true)
    [&quot;type&quot;]=&gt; string(23) &quot;Zend_Navigation_Page_Uri&quot;
    [&quot;pages&quot;]=&gt; array(0) {
    }
    [&quot;uri&quot;]=&gt; string(1) &quot;#&quot;
  }
  [1]=&gt; array(15) {
    [&quot;label&quot;]=&gt; string(6) &quot;Page 2&quot;
    [&quot;id&quot;]=&gt; NULL
    [&quot;class&quot;]=&gt; NULL
    [&quot;title&quot;]=&gt; NULL
    [&quot;target&quot;]=&gt; NULL
    [&quot;rel&quot;]=&gt; array(0) {
    }
    [&quot;rev&quot;]=&gt; array(0) {
    }
    [&quot;order&quot;]=&gt; NULL
    [&quot;resource&quot;]=&gt; NULL
    [&quot;privilege&quot;]=&gt; NULL
    [&quot;active&quot;]=&gt; bool(false)
    [&quot;visible&quot;]=&gt; bool(true)
    [&quot;type&quot;]=&gt; string(23) &quot;Zend_Navigation_Page_Uri&quot;
    [&quot;pages&quot;]=&gt; array(2) {
      [0]=&gt; array(15) {
        [&quot;label&quot;]=&gt; string(8) &quot;Page 2.1&quot;
        [&quot;id&quot;]=&gt; NULL
        [&quot;class&quot;]=&gt; NULL
        [&quot;title&quot;]=&gt; NULL
        [&quot;target&quot;]=&gt; NULL
        [&quot;rel&quot;]=&gt; array(0) {
        }
        [&quot;rev&quot;]=&gt; array(0) {
        }
        [&quot;order&quot;]=&gt; NULL
        [&quot;resource&quot;]=&gt; NULL
        [&quot;privilege&quot;]=&gt; NULL
        [&quot;active&quot;]=&gt; bool(false)
        [&quot;visible&quot;]=&gt; bool(true)
        [&quot;type&quot;]=&gt; string(23) &quot;Zend_Navigation_Page_Uri&quot;
        [&quot;pages&quot;]=&gt; array(0) {
        }
        [&quot;uri&quot;]=&gt; string(1) &quot;#&quot;
      }
      [1]=&gt;
      array(15) {
        [&quot;label&quot;]=&gt; string(8) &quot;Page 2.2&quot;
        [&quot;id&quot;]=&gt; NULL
        [&quot;class&quot;]=&gt; NULL
        [&quot;title&quot;]=&gt; NULL
        [&quot;target&quot;]=&gt; NULL
        [&quot;rel&quot;]=&gt; array(0) {
        }
        [&quot;rev&quot;]=&gt; array(0) {
        }
        [&quot;order&quot;]=&gt; NULL
        [&quot;resource&quot;]=&gt; NULL
        [&quot;privilege&quot;]=&gt; NULL
        [&quot;active&quot;]=&gt; bool(false)
        [&quot;visible&quot;]=&gt; bool(true)
        [&quot;type&quot;]=&gt; string(23) &quot;Zend_Navigation_Page_Uri&quot;
        [&quot;pages&quot;]=&gt; array(0) {
        }
        [&quot;uri&quot;]=&gt; string(1) &quot;#&quot;
      }
    }
    [&quot;uri&quot;]=&gt; string(1) &quot;#&quot;
  }
}
*/
</pre>

        </div>
    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.navigation.pages.html">Pages</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.navigation.html">Zend_Navigation</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.oauth.html">Zend_Oauth</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.navigation.html">Zend_Navigation</a></li>
  <li><a href="zend.navigation.introduction.html">Introduction</a></li>
  <li><a href="zend.navigation.pages.html">Pages</a></li>
  <li class="active"><a href="zend.navigation.containers.html">Containers</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>